/**  
 * @Title: RandomUtil.java
 * @Package com.csun.util
 * @Description: TODO
 * @author chisj chisj@foxmail.com
 * @date 2017年10月11日
 */
package com.csun.cmny.mqtt.utils;

import java.util.Random;

/**
 * ClassName: RandomUtil 
 * @Description: 随机数工具类
 * @author chisj chisj@foxmail.com
 * @date 2017年10月11日
 */
public class RandomUtil {
	
	//方法0
	public static float nextInt(final int min, final int max) {
		Random rand= new Random();
		float tmp = Math.abs(rand.nextFloat());
		float a = tmp + nextInt1(min, max);
		float b = (float)(Math.round(a*100))/100;
		//return (tmp % (max - min + 1) + min);
		return b;
	}
	
	//方法1
	public static int nextInt1(final int min, final int max) {
		Random rand= new Random();
		int tmp = Math.abs(rand.nextInt());
		return (tmp % (max - min + 1) + min);
	}
	
	//方法2：不会生成小于100000的数
	public static int nextInt2() {
		Random random = new Random();
		int x = random.nextInt(899999);
		//int x = x+100000;
		return x;
	}
	
	//方法3
	public static int nextInt3() {
		int n = 0 ;
		while (n < 100000) {
			n = (int)(Math.random()*1000000);
		}
		//System.out.println(n);
		return n;
	}
	
	//方法4
	public static int nextInt4() {
		String str = "";
		str += (int)(Math.random()*9+1);
		for(int i = 0; i < 5; i++){
			str += (int)(Math.random()*10);
		}
		
		int num = Integer.parseInt(str);
		//System.out.println(num);
		
		return num;
	}
	
	//方法5
	//System.out.println((int)((Math.random()*9+1)*100000));
	
	//方法6
	public static String nextInt6() {
		Random random = new Random();
		String result="";
		for(int i=0;i<6;i++){
			result+=random.nextInt(10);
		}
		//System.out.print(result);
		return result;
	}
	
	public static void main(String[] args) {
		
		//System.out.println("random = " + nextInt6());
		for (int i = 0; i < 10; i++) {
			//System.out.println(i + " z = " + nextInt1(90, 93));
			float a = nextInt(90,93);
			System.out.println( i + " random = " + a);
			//float b = (float)(Math.round(a*100))/100;
			//System.out.println( i + " a = " + b);
		}
		
		
	}
}
